document.getElementById('year') ? layui.use(['laydate'], function (laydate) {
  laydate.render({
    elem: '#year',
    type: 'month',
    theme: '#165DFF',
    value: fullYear + "-" + fullMonth,
    //,range: true 
    //,trigger: 'click'
    done: function (value, date, endDate) {
      // console.log(value, date, endDate);
      fullYear = value.split('-')[0]
      fullMonth = value.split('-')[1]

      localStorage.setItem('year', fullYear);
      localStorage.setItem('month', fullMonth);

      change()
    },
    change: function (value, date, endDate) {
      //this.elem.val(value)
    }
  });
}) : ''

function zoomOut() {
  window.location = 'business.html'
}
//默认tab 
let xh = 1
var arr = document.getElementsByTagName('button');
document.addEventListener('click', (e) => {
  console.log(e.target.id)
  if (e.target.id == 'one') {
    console.log(1111)
    xh = 1
    yewuTreeData(xh)
  }
  if (e.target.id == 'two') {
    console.log(22222)
    xh = 2
    yewuTreeData(xh)
  }
})

//获取数据(业务)
function yewuTreeData(xh) {
  console.log(xh, 'xh')
  const username = localStorage.getItem("user");
  const currYear = localStorage.getItem("year");
  const currMon = localStorage.getItem("month");
  const currDept = localStorage.getItem("dept");

  console.log(username, 'username')
  //请求参数
  var obj = {
    username: username,
    budgetYear: currYear,
    budgetMonth: currMon,
    dept: currDept == 'null' ? '' : currDept,
    status: 2,
    chartPage: 2,
    chartNo: xh
  }
  ApiGet('getdata', obj, function (e) {
    console.log('请求ing')
    var json = JSON.parse(e);
    var chartData = json.items[0].charts[0].data;
    if (chartData.length > 0) {
      // console.log(chartData.length)
      // document.getElementById('nodata').style.display = 'none'
      $('#nodata').html(``);

      console.log(chartData, "树形结构数据")
      let treeData = []
      chartData.forEach((item) => {
        let obj = {
          key: item.key01,
          parent: item.key02,
          name: item.key03,
          implementationRate: (item.key10 * 100).toFixed(1),
          dw: '万元',
          ys: '预算金额',
          ysmoney: (item.key04 / 10000).toFixed(2),
          zx: '执行金额',
          zxmoney: (item.key06 / 10000).toFixed(2),

          sy: '剩余金额',
          symoney: (item.key05 / 10000).toFixed(2),
          datasets: [{
            backgroundColor: ['#165DFF', "#F2F3F5"],
            data: makeRandomPoints(item.key10 * 100)
          }],
          moji: item.key11,
          // feiyongType: item.key12
          feiyongType: '点击跳转'
        }
        treeData.push(obj);
      })
      let firstArr = {
        key: treeData[0].key,
        parent: treeData[0].parent,
        ALL_name: treeData[0].name,
        ALL_implementationRate: treeData[0].implementationRate,
        ALL_dw: '万元',
        ALL_zx: '执行金额',
        ALL_zxmoney: treeData[0].zxmoney,
        ALL_ys: '预算金额',
        ALL_ysmoney: treeData[0].ysmoney,
        ALL_sy: '剩余金额',
        ALL_symoney: treeData[0].symoney,
        ALL_datasets: treeData[0].implementationRate,
        // feiyongType: treeData[0].feiyongType
        feiyongType: ''

      }
      //修改数组中的第一个对象 
      treeData = treeData.map(item => {
        return item.key === firstArr.key ? firstArr : item;
      })
      console.log(treeData[0], '修改数组中的第一个对象 ')


      var myDiagramDiv1 = document.getElementById('myDiagramDiv1');
      var wrapper = document.getElementById('wrapper');
      wrapper.removeChild(myDiagramDiv1)
      var div = document.createElement('div');
      div.setAttribute('id', 'myDiagramDiv1')
      wrapper.appendChild(div);

      var G = go.GraphObject.make;
      var myDiagram =
        G(go.Diagram, "myDiagramDiv1", {
          initialAutoScale: go.Diagram.Uniform,
          "toolManager.mouseWheelBehavior": go.ToolManager.WheelZoom,
          initialDocumentSpot: go.Spot.Top,
          initialViewportSpot: go.Spot.Top,

          initialContentAlignment: go.Spot.Top, // 居中显示Diagram内容
          // "undoManager.isEnabled": true, // 打开ctrl-z撤销和ctrl-y重做功能
          layout: G(go.TreeLayout, //1个特殊的树形排列Diagram.layout布局
            {
              angle: 90,
              layerSpacing: 50,
            })
        });



      function textStyle(field) {
        if (field == "ALL_name") {
          return [{
              font: "bold 16pt sans-serif",
              stroke: "#000",
              visible: false //仅在有数据时候显示
            },
            new go.Binding("visible", field, val => val !== undefined)
          ]
        }
        return [{
            font: "bold 14pt sans-serif",
            stroke: "#000",
            visible: false //仅在有数据时候显示
          },
          new go.Binding("visible", field, val => val !== undefined)
        ]
      }

      function fontextStyle(field) {
        if (field == "ys" || "zx" || "sy") {
          return [{
              font: "12pt  Segoe UI,sans-serif",
              stroke: "#4E5969",
              visible: false //仅在有数据时候显示
            },
            new go.Binding("visible", field, val => val !== undefined)
          ]
        }
        return [{
            font: "12pt  Segoe UI,sans-serif",
            stroke: "#4E5969",
            visible: false //仅在有数据时候显示
          },
          new go.Binding("visible", field, val => val !== undefined)
        ]
        // return { font: "12pt  Segoe UI,sans-serif", stroke: "gray" };
      }

      function dwtextStyle(field) {
        if (field == "ALL_dw") {
          return [{
              font: "9pt  Segoe UI,sans-serif",
              stroke: "#4E5969",

              visible: false //仅在有数据时候显示
            },
            new go.Binding("visible", field, val => val !== undefined)
          ]
        }
        return [{
            font: "9pt  Segoe UI,sans-serif",
            stroke: "#4E5969",
            visible: false //仅在有数据时候显示
          },
          new go.Binding("visible", field, val => val !== undefined)
        ]
        // return { font: "9pt  Segoe UI,sans-serif", stroke: "gray" };
      }

      function moneytextStyle(field) {
        if (field == "ALL_zxmoney" || "ALL_ysmoney" || "ALL_symoney") {
          return [{
              font: "bold 14pt sans-serif",
              stroke: "#1D2129",
              visible: false //仅在有数据时候显示
            },
            new go.Binding("visible", field, val => val !== undefined)
          ]
        }
        return [{
            font: "bold 14pt sans-serif",
            stroke: "#1D2129",
            visible: false //仅在有数据时候显示
          },
          new go.Binding("visible", field, val => val !== undefined)
        ]
        // return { font: "bold 14pt sans-serif", stroke: "#000" };
      }

      myDiagram.nodeTemplate =
        G(go.Node, "Auto", {
            isTreeExpanded: false,
            selectionObjectName: "BODY",
            deletable: true,
            locationSpot: go.Spot.Top,
            isShadowed: true,
            shadowBlur: 10,
          },
          // 定义节点的外部形状
          G(go.Shape, "RoundedRectangle", {
            name: "SHAPE",
            fill: "#fff",
            strokeWidth: 0,
            portId: "",
            cursor: "pointer",
            // click: tanchuMask
          }),
          G(go.Panel, "Vertical", {
              defaultStretch: go.GraphObject.Horizontal,
            },
            //个部分名称
            G(go.Panel, "Table",
              G(go.TextBlock, textStyle("name"), // 名称
                {
                  // row: 1, column: 1,
                  font: "bold 14pt sans-serif",
                  editable: true,
                  isMultiline: false,
                  minSize: new go.Size(10, 16),
                  margin: 8,
                  alignment: go.Spot.Center
                },
                new go.Binding("text", "name").makeTwoWay()),
              G(go.TextBlock, textStyle("ALL_name"), // 名称---全面预算
                {
                  row: 1,
                  column: 1,
                  font: "bold 16pt sans-serif",
                  editable: true,
                  isMultiline: false,
                  minSize: new go.Size(10, 16),
                  margin: 10,
                  alignment: go.Spot.Center
                },
                new go.Binding("text", "ALL_name").makeTwoWay(), ),
            ),

            // echarts部分
            G(go.Panel, "Table", {
                stretch: go.GraphObject.Horizontal,
                width: 200,
                height: 80,
                margin: 15,
                visible: false,
                background: "#E8F3FF",

              },
              new go.Binding("visible", "implementationRate", imp => imp !== undefined),
              G(go.TextBlock, // 执行率
                {
                  row: 0,
                  column: 0,
                  font: "bold 16pt sans-serif",
                  alignment: go.Spot.Right,
                  stroke: "#165DFF",
                },
                new go.Binding("text", "implementationRate").makeTwoWay()),
              G(go.TextBlock, "%", // 执行率
                {
                  row: 0,
                  column: 1,
                  font: "bold 9pt sans-serif",
                  margin: 10,
                  alignment: go.Spot.Left,
                  stroke: "#165DFF",
                },
              ),
              G(go.TextBlock, "执行率", // 执行率
                {
                  row: 1,
                  column: 0,
                  font: "bold 9pt sans-serif",
                  stroke: "#4E5969",
                  // minSize: new go.Size(30, 16),
                  margin: new go.Margin(-5, 0, 10, 0),
                  alignment: go.Spot.Right,

                },
              ),

            ),
            // notes部分
            G(go.Panel, "Table", {
                // minSize: new go.Size(280, NaN),
                // // maxSize: new go.Size(280, NaN),
                margin: new go.Margin(6, 10, 0, 6),
                stretch: go.GraphObject.Horizontal,
                defaultAlignment: go.Spot.Left, //对齐方式

              },
              G(go.Panel, "Table",
                G(go.TextBlock, fontextStyle("ALL_ys"), { //全面预算--执行金额
                    row: 1,
                    column: 1,
                    rowSpan: 4,
                    margin: new go.Margin(5, 20, 5, 20)
                  },
                  new go.Binding("text", "ALL_ys")
                ),
                G(go.TextBlock, moneytextStyle("ALL_ysmoney"), {
                    row: 5,
                    column: 1,
                  },
                  new go.Binding("text", "ALL_ysmoney")
                ),
                G(go.TextBlock, dwtextStyle("ALL_dw"), {
                    row: 5,
                    column: 2,
                  },
                  new go.Binding("text", "ALL_dw").makeTwoWay()),

                G(go.TextBlock, fontextStyle("ALL_zx"), { //全面预算--预算金额
                    row: 1,
                    column: 4,
                    rowSpan: 4,
                    margin: new go.Margin(0, 20, 0, 20)
                  },
                  new go.Binding("text", "ALL_zx")
                ),
                G(go.TextBlock, moneytextStyle("ALL_zxmoney"), {
                    row: 5,
                    column: 4,
                  },
                  new go.Binding("text", "ALL_zxmoney")
                ),
                G(go.TextBlock, dwtextStyle("ALL_dw"), {
                    row: 5,
                    column: 5,
                  },
                  new go.Binding("text", "ALL_dw").makeTwoWay()),
                G(go.TextBlock, fontextStyle("ALL_sy"), {
                    row: 1,
                    column: 8,
                    rowSpan: 4,
                    margin: new go.Margin(0, 20, 0, 20)
                  },
                  new go.Binding("text", "ALL_sy")
                ),
                G(go.TextBlock, moneytextStyle("ALL_symoney"), {
                    row: 5,
                    column: 8,
                  },
                  new go.Binding("text", "ALL_symoney")
                ),
                G(go.TextBlock, dwtextStyle("ALL_dw"), {
                    row: 5,
                    column: 9,
                  },
                  new go.Binding("text", "ALL_dw").makeTwoWay()),
              ),

              G(go.TextBlock, fontextStyle("ys"), // 预算金额:
                {
                  row: 4,
                  column: 0,
                  margin: 5
                },
                new go.Binding("text", "ys").makeTwoWay()
              ),
              G(go.TextBlock, moneytextStyle("ysmoney"), //  预算金额:(data)
                {
                  row: 4,
                  column: 8,
                  editable: true,
                  isMultiline: false,
                  minSize: new go.Size(10, 14),
                  margin: new go.Margin(0, 0, 0, 5),
                  alignment: go.Spot.Right,
                },
                new go.Binding("text", "ysmoney").makeTwoWay()),

              G(go.TextBlock, dwtextStyle("dw"), //单位
                {
                  row: 4,
                  column: 10,
                  margin: new go.Margin(0, 0, 0, 5)
                },
                new go.Binding("text", "dw").makeTwoWay()),
              // 111111111111111111111111
              G(go.TextBlock, fontextStyle("zx"), //执行金额
                {
                  row: 6,
                  column: 0,
                  margin: 5
                },
                new go.Binding("text", "zx").makeTwoWay()
              ),
              G(go.TextBlock, moneytextStyle("zxmoney"), {
                  row: 6,
                  column: 8,
                  editable: true,
                  isMultiline: false,
                  minSize: new go.Size(10, 14),
                  alignment: go.Spot.Right,
                },
                new go.Binding("text", "zxmoney").makeTwoWay()),
              G(go.TextBlock, dwtextStyle("dw"), {
                  row: 6,
                  column: 10,
                  margin: new go.Margin(0, 0, 0, 5)
                },
                new go.Binding("text", "dw").makeTwoWay()),

              G(go.TextBlock, fontextStyle("sy"), { // 剩余金额
                  row: 8,
                  column: 0,
                  margin: 5
                },
                new go.Binding("text", "sy").makeTwoWay()
              ),
              G(go.TextBlock, moneytextStyle("symoney"), {
                  row: 8,
                  column: 8,
                  editable: true,
                  isMultiline: false,
                  minSize: new go.Size(10, 14),
                  alignment: go.Spot.Right,
                  // margin: new go.Margin(0, 0, 0, 5)
                },
                new go.Binding("text", "symoney").makeTwoWay()),
              G(go.TextBlock, dwtextStyle("dw"), {
                  row: 8,
                  column: 10,
                  margin: new go.Margin(0, 0, 0, 5)
                },
                new go.Binding("text", "dw").makeTwoWay()),
            ),
            // 进度条部分
            G(go.Panel, "Auto", {
                stretch: go.GraphObject.Horizontal,
                visible: false,
                // background: 'pink',
                margin: new go.Margin(20, 20, 10, 20),
              },
              new go.Binding("visible", "ALL_datasets", imp => imp !== undefined),
              G(go.TextBlock, "执行率", {
                font: "12pt  Segoe UI,sans-serif",
                stroke: "#4E5969",
              }),
              // 进度条
              G(go.Panel,
                G(go.TextBlock, {
                  background: '#F2F3F5',
                  width: 230,
                  height: 12
                }),
                G(go.TextBlock, {
                  background: '#165DFF',
                  width: makeProcessChart(),
                  height: 12,
                }, ),
              ),

              G(go.TextBlock, moneytextStyle("ALL_datasets"), {
                  alignment: go.Spot.Right,
                  margin: new go.Margin(0, 15, 0, 0),
                },
                new go.Binding("text", "ALL_datasets").makeTwoWay()
              ),
              G(go.TextBlock, "%", {
                alignment: go.Spot.Right,
              }, ),
            ),
            //操作按钮
            G(go.Panel, "Table", {
                stretch: go.GraphObject.Horizontal,
                margin: new go.Margin(10, 20, 0, 20),
              },
              new go.Binding("visible", "feiyongType", feiyongType => feiyongType !== ''),
              // G("Button", {
              //     stretch: go.GraphObject.Horizontal,
              //     alignment: go.Spot.Left,
              //     height: 20,
              //     width: 80,
              //     "ButtonBorder.figure": 'RoundedRectangle',
              //     "ButtonBorder.fill": "#F2F3F5",
              //     "ButtonBorder.stroke": "#F2F3F5",
              //     "_buttonFillOver": "#165DFF",
              //     "_buttonStrokeOver": "#165DFF",
              //     "_buttonFillPressed": "#165DFF",
              //     click: tanchuMask,
              //   },
              //   G(go.TextBlock, "关系图")

              //   // G(go.TextBlock, {
              //   //     font: "14px  Segoe UI,sans-serif",
              //   //     stroke: "#4E5969",
              //   //   },
              //   //   new go.Binding("text", "feiyongType").makeTwoWay()
              //   // ),

              // ),
              G("Button", {
                  stretch: go.GraphObject.Horizontal,
                  alignment: go.Spot.Center,
                  height: 40,
                  width: 100,
                  "ButtonBorder.figure": 'RoundedRectangle',
                  "ButtonBorder.fill": "#F2F3F5",
                  "ButtonBorder.stroke": "#F2F3F5",
                  "_buttonFillOver": "#E8F3FF",
                  "_buttonStrokeOver": "#E8F3FF",
                  "_buttonFillPressed": "#E8F3FF",
                  "_aaa": 1111,
                  click: tiaozhuan
                },
                G(go.TextBlock, "详细执行情况")
                // G(go.TextBlock, {
                //     font: "14px  Segoe UI,sans-serif",
                //     stroke: "#4E5969",
                //   },
                //   new go.Binding("text", "feiyongType").makeTwoWay()
                // ),

              ),
            ),
            //折叠展开按钮+
            G(go.Panel, "Table", {
                margin: new go.Margin(20, 0, 0, 0),
                height: 17,
                alignment: go.Spot.Center,
              },
              G("TreeExpanderButton", {
                "ButtonBorder.fill": "#4E5969",
                "ButtonBorder.figure": "Circle",
                "_buttonFillOver": "#165DFF",
                "_buttonStrokeOver": "#165DFF",
                "_buttonFillPressed": "#FFF",
              }, )
            ),
          ));

      //弹窗
      function tanchuMask(e, obj) {
        var n = myDiagram.selection.first();
        console.log(n)
        if (n === null) return;
        var d = n.data;
        let budgetNo = d.key
        let budgetName = d.name

        if (budgetNo != 0001) {
          console.log(budgetNo, '')
          localStorage.setItem('budgetNo', budgetNo);
          localStorage.setItem('budgetName', budgetName);

          // window.location.href = "guanxitu.html"
        } else {
          console.log('全面预算（第一层级？展开关系图）')
        }

        if (d.feiyongType == '材料费') {
          const currYear = localStorage.getItem("year");
          const currMon = localStorage.getItem("month");
          $.get(
            `${API_URL}getdata?budgetYear=${currYear}&budgetMonth=${currMon}&status=2&chartNo=1&chartPage=201`, {},
            function (res) {
              $('.mask-wrap').show()
              let re = eval("(" + res + ")");
              let data = re.items[0].charts[0].data;
              let leibie = '';
              let bumen = '';
              for (let i = 0; i < data.length; i++) {
                if (data[i].key03 == '材料费') {
                  if (data[i].key04 == '材料类别') {
                    leibie += `<div class="item">
                      <p>${data[i].key05}</p >
                      <h4>${data[i].key06}<span>万元</span></h4>
                     </div>`
                  }
                }
              }
              if (leibie != '') {
                leibie = `<div class="box else">
                       <h5>材料类别支出</h5>
                       <div class="items">` + leibie + `</div>
                      </div>`
              }
              $.get(
                `${API_URL}getdata?budgetYear=${currYear}&budgetMonth=${currMon}&status=2&chartNo=2&key01=${d.key}&chartPage=201`, {},
                function (res) {
                  let re = eval("(" + res + ")");
                  let data = re.items[0].charts[0].data;
                  for (let i = 0; i < data.length; i++) {
                    bumen += `<div class="item">
                       <p>${data[i].key03}</p >
                       <h4>${data[i].key05}<span>万元</span></h4>
                      </div>`
                  }
                  if (bumen != '') {
                    bumen = `<div class="box else">
                     <h5>部门支出</h5>
                     <div class="items">` + bumen + `</div>
                      </div>`
                  }
                  $('.mask-wrap').html(`<div class="mask-position">
                     <div class="mask-content">
                      <div class="mask-title">
                       <h4>材料费</h4>
                       <img src="assets/images/mask/close.png">
                      </div>
                      <div class="mask-scroll">
                       <div class="info">
                        ${leibie}
                        ${bumen}
                       </div>
                       <div class="monthly">
                        <h5>月度支出</h5>
                        <div class="chart" id="cailiao_chart"></div>
                       </div>
                      </div>
                     </div>
                    </div>`)

                  cailiao(d.key)
                })

            })

        } else if (d.feiyongType == '外协费') {
          const currYear = localStorage.getItem("year");
          const currMon = localStorage.getItem("month");
          $.get(
            `${API_URL}getdata?budgetYear=${currYear}&budgetMonth=${currMon}&status=2&chartNo=1&chartPage=201`, {},
            function (res) {
              $('.mask-wrap').show()
              let re = eval("(" + res + ")");
              let data = re.items[0].charts[0].data;
              let danwei = '';
              let keti = ''
              let bumen = '';
              for (let i = 0; i < data.length; i++) {
                if (data[i].key03 == '外协费') {
                  if (data[i].key04 == '往来单位') {
                    danwei += `<div class="item">
                      <p>${data[i].key05}</p >
                      <h4>${data[i].key06}<span>万元</span></h4>
                     </div>`
                  } else if (data[i].key04 == '主要课题') {
                    keti += `<div class="item">
                      <p>${data[i].key05}</p >
                      <h4>${data[i].key06}<span>万元</span></h4>
                     </div>`
                  }
                }
              }
              if (danwei != '') {
                danwei = `<div class="box btype">
                       <h5>主要往来单位</h5>
                       <div class="items">` + danwei + `</div>
                      </div>`
              }
              if (keti != '') {
                keti = `<div class="box else">
                       <h5>主要课题</h5>
                       <div class="items">` + keti + `</div>
                      </div>`
              }
              $.get(
                `${API_URL}getdata?budgetYear=${currYear}&budgetMonth=${currMon}&status=2&chartNo=2&key01=${d.key}&chartPage=201`, {},
                function (res) {
                  let re = eval("(" + res + ")");
                  let data = re.items[0].charts[0].data;
                  for (let i = 0; i < data.length; i++) {
                    bumen += `<div class="item">
                         <p>${data[i].key03}</p >
                         <h4>${data[i].key05}<span>万元</span></h4>
                        </div>`
                  }
                  if (bumen != '') {
                    bumen = `<div class="box else">
                       <h5>部门支出</h5>
                       <div class="items">` + bumen + `</div>
                      </div>`
                  }
                  $('.mask-wrap').html(`<div class="mask-position">
                     <div class="mask-content">
                      <div class="mask-title">
                       <h4>外协费</h4>
                       <img src="assets/images/mask/close.png">
                      </div>
                      <div class="mask-scroll">
                       <div class="info">
                        ${danwei}
                        ${keti}
                        ${bumen}
                       </div>
                       <div class="monthly">
                        <h5>月度支出</h5>
                        <div class="chart" id="waixie_chart"></div>
                       </div>
                      </div>
                     </div>
                    </div>`)
                  waixie(d.key)
                })
            })
        } else if (d.feiyongType == '工资') {
          const currYear = localStorage.getItem("year");
          const currMon = localStorage.getItem("month");
          $.get(
            `${API_URL}getdata?budgetYear=${currYear}&budgetMonth=${currMon}&status=2&chartNo=1&chartPage=201`, {},
            function (res) {
              $('.mask-wrap').show()
              let re = eval("(" + res + ")");
              let data = re.items[0].charts[0].data;
              let leibie = '';
              let xinchou = '';
              let bumen = '';
              for (let i = 0; i < data.length; i++) {
                if (data[i].key03 == '工资') {
                  if (data[i].key04 == '人员类别') {
                    leibie += `<div class="item">
                      <p>${data[i].key05}</p >
                      <h4>${data[i].key06}<span>万元</span></h4>
                     </div>`
                  } else if (data[i].key04 == '薪酬类别') {
                    xinchou += `<div class="item">
                      <p>${data[i].key05}</p >
                      <h4>${data[i].key06}<span>万元</span></h4>
                     </div>`
                  }
                }
              }
              if (leibie != '') {
                leibie = `<div class="box else">
                      <h5>人员类别薪酬分布</h5>
                      <div class="items">` + leibie + `</div>
                     </div>`
              }
              if (xinchou != '') {
                xinchou = `<div class="box else">
                      <h5>薪酬类别分布</h5>
                      <div class="items">` + xinchou + `</div>
                     </div>`
              }
              $.get(
                `${API_URL}getdata?budgetYear=${currYear}&budgetMonth=${currMon}&status=2&chartNo=2&key01=${d.key}&chartPage=201`, {},
                function (res) {
                  let re = eval("(" + res + ")");
                  let data = re.items[0].charts[0].data;
                  for (let i = 0; i < data.length; i++) {
                    bumen += `<div class="item">
                       <p>${data[i].key03}</p >
                       <h4>${data[i].key05}<span>万元</span></h4>
                      </div>`
                  }
                  if (bumen != '') {
                    bumen = `<div class="box else">
                      <h5>部门薪酬</h5>
                      <div class="items">` + bumen + `</div>
                      </div>`
                  }
                  $('.mask-wrap').html(`<div class="mask-position">
                    <div class="mask-content">
                     <div class="mask-title">
                      <h4>工资</h4>
                      <img src="assets/images/mask/close.png">
                     </div>
                     <div class="mask-scroll">
                      <div class="info">
                       ${leibie}
                       ${xinchou}
                       ${bumen}
                      </div>
                      <div class="monthly">
                       <h5>月度薪酬</h5>
                       <div class="chart" id="gongzi_chart"></div>
                      </div>
                     </div>
                    </div>`)
                  gongzi(d.key)
                })

            }
          )
        }
      }
      //跳转
      function tiaozhuan(e, obj) {
        // console.log(e, obj, '即将跳转到新页面')
        // var n = myDiagram.selection.first();
        // console.log(n)
        // if (n === null) return;
        // var d = n.data;
        var node = obj.part;
        var d = node.data;

        let budgetNo = d.key
        let budgetName = d.name
        if (budgetNo != 0001) {
          console.log(budgetNo, '')
          localStorage.setItem('budgetNo', budgetNo);
          localStorage.setItem('budgetName', budgetName);
          // window.location.href = "implementation-rate.html"
		  $('#rateMask').show()
		  getImplementationRate()
        }
      }
      //进度条
      function makeProcessChart() {
        let arr = treeData[0].ALL_datasets.split('%')
        let width = arr[0] / 100 * 230
        return width;
      }
      //环形图
      function makeLineChart(datasets, picture) {
        var canvases = document.getElementById("myCanvases");
        canv = document.createElement("canvas");
        canv.width = canv.style.width = "600px";
        canv.height = canv.style.height = "300px";

        var div = document.createElement("div");
        div.style.position = "absolute";
        div.appendChild(canv);
        canvases.appendChild(div);

        var config = { // Chart.js 配置, 包括来自模型 DATASETS 数据  data
          type: 'doughnut',
          data: {
            datasets: datasets
          },
          options: {
            cutoutPercentage: 75,
            responsive: true,
            // plugins: {
            //   legend: {
            //     position: 'top',
            //   },
            //   title: {
            //     display: true,
            //     text: 'Chart.js Doughnut Chart'
            //   }
            // }
          },
        };
        new Chart(canv, config);
        return canv;
      }
      //计算环形数组
      function makeRandomPoints(data) {
        var pts = [];
        let num = 0;
        pts.push(data);
        if (data) {
          num = 100 - data
        }
        pts.push(num);
        return pts;
      }

      myDiagram.linkTemplate =
        G(go.Link, {
            routing: go.Link.Orthogonal,
            deletable: false,
            corner: 10
          },
          G(go.Shape, {
            strokeWidth: 1,
            stroke: "#CED1D9"
          }),
        );
      var model = G(go.TreeModel);
      myDiagram.addDiagramListener("InitialLayoutCompleted", function (e) {
        e.diagram.findTreeRoots().each(function (r) {
          r.expandTree(2);
        });
      });

      model.nodeDataArray = treeData
      myDiagram.model = model;
    } else {
      var chartData = [];
      document.getElementById("myDiagramDiv1").style.display = "none";
      console.log(chartData.length, '长度')
      // document.getElementById('nodata').style.display = 'block'
      $('#nodata').html(` <div
      style=" margin: 100px auto; background-color: #FFFFFF; width: 300px; text-align: center; height: 150px; border-radius: 24px; line-height: 1.5; padding: 60px 0; color: #7D8A9F; box-shadow: 10px 10px 5px #888888;">
      暂无数据！</div>`)
    }
  });
  // window.addEventListener('DOMContentLoaded', init);
}

go.GraphObject.defineBuilder('TreeExpanderButton', function (args) {
  var button = /** @type {Panel} */ (
    go.GraphObject.make('Button', { // 为isTreeExpanded绑定转换设置这些值
        '_treeExpandedFigure': 'MinusLine',
        '_treeCollapsedFigure': 'PlusLine'
      },
      go.GraphObject.make(go.Shape, // 图标
        {
          name: 'ButtonIcon',
          figure: 'MinusLine', // isTreeExpanded的默认值为true
          stroke: '#fff',
          strokeWidth: 2,
          desiredSize: new go.Size(8, 8)
        },
        //绑定形状。将图形添加到节点。isTreeExpanded值使用此转换器：
        new go.Binding('figure', 'isTreeExpanded',
          function (exp, shape) {
            var but = shape.panel;
            return exp ? but['_treeExpandedFigure'] : but['_treeCollapsedFigure'];
          }
        ).ofObject()
      ),
      // 假设最初不可见，因为没有链接出来
      {
        visible: false
      },
      //将按钮可见性绑定到它是否为叶节点
      new go.Binding('visible', 'isTreeLeaf',
        function (leaf) {
          return !leaf;
        }
      ).ofObject()
    )
  );

  // tree expand/collapse behavior
  button.click = function (e, btn) {
    var node = btn.part;
    if (node instanceof go.Adornment) node = node.adornedPart;
    if (!(node instanceof go.Node)) return;
    var diagram = node.diagram;
    if (diagram === null) return;
    var cmd = diagram.commandHandler;
    if (node.isTreeExpanded) {
      if (!cmd.canCollapseTree(node)) return;
    } else {
      if (!cmd.canExpandTree(node)) return;
    }
    e.handled = true;
    if (node.isTreeExpanded) {
      cmd.collapseTree(node);
    } else {
      cmd.expandTree(node);
    }
  };
  return button;
});